package com.example.drcbackend.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.drcbackend.Mapper.DbMapper;
import com.example.drcbackend.Mapper.SubsetdbMapper;
import com.example.drcbackend.entity.Db;
import com.example.drcbackend.entity.Subsetdb;
import com.example.drcbackend.jwt.Result;
import com.example.drcbackend.service.ConsistencyService;
import com.example.drcbackend.service.RepairCheckResult;
import com.example.drcbackend.service.RepairCheckingService;
import com.example.drcbackend.service.SubsetService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("/rp")
@RestController
@CrossOrigin
public class Repair_CheckingController {
    private static final Logger logger = LoggerFactory.getLogger(ConsistencyController.class);
    @Autowired
    private SubsetdbMapper sm;
    @Autowired
    private DbMapper dm;

    @Autowired
    private SubsetService subsetservice;

    @Autowired
    private ConsistencyService consistencyService;
    @Autowired
    private RepairCheckingService rcservice;
    @PostMapping("/subset_checking")// 子集检查
    public Result subset_checking(int setid) {
        Subsetdb set = sm.selectById(setid);
       return Result.ok().data("sub_result",subsetservice.CheckSubset(set.getDbid(),set.getSetdbid()));
    }

    @PostMapping("/repair_checking")
    public Result repair_checking(int setid) {
        Subsetdb set = sm.selectById(setid);
        RepairCheckResult checkResult = rcservice.RepairChecking(set.getDbid(), set.getSetdbid());
        Result result = Result.ok()
                .data("check_result", checkResult.isResult())
                .data("constant_c", checkResult.getConstantC());
        if (checkResult.isResult()==false) {// 修复检查未通过返回这个非空集合A*
            result.data("a_star", checkResult.getAStar());
        }
        return result;
    }
}
